package com.jic.data.controller;

import com.jic.data.model.entity.SalesDetailData;
import com.jic.data.model.entity.SalesPlatformAmount;
import com.jic.data.model.entity.SalesReginAmount;
import com.jic.data.model.vo.request.SalesDetailDataRequest;
import com.jic.data.model.vo.request.SalesPlatformAmountRequest;
import com.jic.data.model.vo.request.SalesReginAmountRequest;
import com.jic.data.model.vo.response.*;
import com.jic.data.service.SalesDetailDataService;
import com.jic.data.service.SalesPlatformAmountService;
import com.jic.data.service.SalesReginAmountService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.beans.BeanUtils;

import java.util.List;
import java.util.stream.Collectors;

import com.jic.common.base.vo.RestResult;
import lombok.extern.slf4j.Slf4j;
import com.jic.data.model.vo.request.SaleOverviewBaseDataRequest;
import com.jic.data.model.entity.SaleOverviewBaseData;
import com.jic.data.service.SaleOverviewBaseDataService;

/**
 * @Author: 建投数据科技(山东)有限公司
 * @date: 2020-05-09 17:25:19
 */
@RestController
@Slf4j
@RequestMapping("/overview")
@Api(tags = "销售概览")
public class SaleOverviewBaseDataController {

    @Autowired
    private SaleOverviewBaseDataService saleOverviewBaseDataService;

    @Autowired
    private SalesPlatformAmountService platformAmountService;

    @Autowired
    private SalesReginAmountService salesReginAmountService;

    @Autowired
    private SalesDetailDataService salesDetailDataService;


    /**
     * 销售概览数据查询
     *
     * @param request 前端请求参数
     */
    @PostMapping("/list/base")
    @ApiOperation(value = "销售概览-销售概览基本数据")
    @ResponseBody
    public RestResult<SaleOverviewBaseDataResponse> listSaleOverviewBaseDataAllRecord(@RequestBody SaleOverviewBaseDataRequest request) throws Throwable {
        SaleOverviewBaseData saleOverviewBaseData = new SaleOverviewBaseData();
        BeanUtils.copyProperties(request, saleOverviewBaseData);
        SaleOverviewBaseDataResponse response = saleOverviewBaseDataService.listAllRecord(saleOverviewBaseData);

        return RestResult.success(response);
    }


    @PostMapping("/query/amount/order")
    @ApiOperation(value = "销售概览-销售趋势")
    @ResponseBody
    public RestResult<HistogramChartResponse>  queryEveryDayAmountOrder(@RequestBody SaleOverviewBaseDataRequest request) throws Throwable {
        SaleOverviewBaseData saleOverviewBaseData = new SaleOverviewBaseData();
        BeanUtils.copyProperties(request, saleOverviewBaseData);

        HistogramChartResponse response = saleOverviewBaseDataService.queryEveryDayAmountOrder(saleOverviewBaseData);
        return RestResult.success(response);
    }




    /**
     * 销售平台分布查询
     *
     * @param request 前端请求参数
     */
    @PostMapping("/list/platform")
    @ApiOperation(value = "[销售概览-平台销售分布]")
    @ResponseBody
    public RestResult<HistogramChartResponse> listSalesPlatformAmountAllRecord(@RequestBody SalesPlatformAmountRequest request) throws Throwable {
        SalesPlatformAmount salesPlatformAmount = new SalesPlatformAmount();
        BeanUtils.copyProperties(request, salesPlatformAmount);
        HistogramChartResponse response = platformAmountService.listAllRecord(salesPlatformAmount);

        return RestResult.success(response);
    }




    @PostMapping("/list/regin")
    @ApiOperation(value = "查询区域销售额占比")
    @ResponseBody
    public RestResult<List<PieChartResponse>> listReginAmount(SalesReginAmountRequest request) {
        SalesReginAmount amount = new SalesReginAmount();
        BeanUtils.copyProperties(request, amount);
        List<PieChartResponse> response = salesReginAmountService.selectReginAmount(amount);
        return RestResult.success(response);
    }



    @PostMapping("/list/province")
    @ApiOperation(value = "查询省份销售额")
    @ResponseBody
    public RestResult<List<PieChartResponse>> listProvinceAmount(SalesReginAmountRequest request) {
        SalesReginAmount amount = new SalesReginAmount();
        BeanUtils.copyProperties(request, amount);
        List<PieChartResponse> response = salesReginAmountService.selectProvinceAmount(amount);
        return RestResult.success(response);
    }


    @PostMapping("/list/detail")
    @ApiOperation(value = "销售概览明细数据")
    @ResponseBody
    public RestResult<List<SalesDetailDataResponse>> listDetailData(SalesDetailDataRequest request) {
        SalesDetailData salesPlatformAmount = new SalesDetailData();
        BeanUtils.copyProperties(request, salesPlatformAmount);
        List<SalesDetailDataResponse> responseList = salesDetailDataService.listAllRecord(salesPlatformAmount);
        return RestResult.success(responseList);
    }

}

